package com.yearner.reviewplan.common.aspect;

import org.aspectj.lang.JoinPoint;

import java.lang.reflect.Method;

/**
 * @author pengyg
 * @since 2019/12/5
 */
public class CommomAspectFunction {
    /**
     * 获取切面注解的方法
     *
     * @param joinPoint 切点
     * @return 描述信息
     * @throws Exception
     */
    public static Method getAspectMethod(JoinPoint joinPoint)
            throws Exception {
        String targetName = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        Object[] arguments = joinPoint.getArgs();
        Class targetClass = Class.forName(targetName);
        Method[] methods = targetClass.getMethods();
        StringBuilder description = new StringBuilder("");
        for (Method method : methods) {
            if (method.getName().equals(methodName)) {
                Class[] clazzs = method.getParameterTypes();
                if (clazzs.length == arguments.length) {
                    return method;
//                    description.append(method.getAnnotation(AuthTokenV1.class).function());
//                    break;
                }
            }
        }
        throw new RuntimeException("没有找到切点对应的方法!");
    }
}
